import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    // token 状态
    const token = ref('')
    const setToken = (t) => {
      token.value = t
    }

    // captchaKey 状态
    const captchaKey = ref('')
    const setCaptchaKey = (key) => {
      captchaKey.value = key
    }

    return { token, setToken, captchaKey, setCaptchaKey }
  },
  {
    persist: {
      storage: {
        getItem: (key) => sessionStorage.getItem(key),
        setItem: (key, value) => sessionStorage.setItem(key, value),
      },
    },
  }
)
